####################################################################
# Replication code for
#   Lyall, Shiraito, and Imai, "Coethnic Bias and Wartime Informing"
#
# Code to create Figure 3 and 4 in the paper, Figures 6-22 in the
# Supplemental Appendix, and Tables 6 and 8 in the Supplemental
# Appendix
#
# Author: Yuki Shiraito
# Created: March 2, 2015
####################################################################

rm(list = ls())
library(coda)

km.setting <- 2  ## change this to 5 to create figures for the 5-km model

load("treat.RData")

###
### Load posterior samples
###
load(paste("Posterior_", km.setting, "km.RData", sep = ""))

endorse.out1 <- endorse.out.list[[1]]
endorse.out2 <- endorse.out.list[[2]]
endorse.out3 <- endorse.out.list[[3]]

#### Combine the latter halves of three chains for posterior analysis
sample.size <- nrow(endorse.out1$lambda)

sample.beta <- as.mcmc(rbind(endorse.out1$beta,
                       endorse.out2$beta,
                       endorse.out3$beta))

sample.tau <- as.mcmc(rbind(endorse.out1$tau,
                       endorse.out2$tau,
                       endorse.out3$tau))

sample.lambda <- as.mcmc(rbind(endorse.out1$lambda,
                       endorse.out2$lambda,
                       endorse.out3$lambda))

sample.kappa <- as.mcmc(rbind(endorse.out1$kappa,
                      endorse.out2$kappa,
                      endorse.out3$kappa))

sample.delta <- as.mcmc(rbind(endorse.out1$delta,
                      endorse.out2$delta,
                      endorse.out3$delta))

sample.zeta <- as.mcmc(rbind(endorse.out1$zeta,
                      endorse.out2$zeta,
                      endorse.out3$zeta))

sample.x <- as.mcmc(rbind(endorse.out1$x,
                          endorse.out2$x,
                          endorse.out3$x))

x.sd <- as.double(rbind(endorse.out1$x.sd,
                        endorse.out2$x.sd,
                        endorse.out3$x.sd))

sample.sig2 <- as.double(rbind(endorse.out1$sig2,
                               endorse.out2$sig2,
                               endorse.out3$sig2))

sample.omega2 <- as.mcmc(rbind(endorse.out1$omega2,
                               endorse.out2$omega2,
                               endorse.out3$omega2))

s.ncol <- ncol(endorse.out1$s)
sample.s.Q1 <- as.mcmc(rbind(endorse.out1$s[, seq(from = 1, to = s.ncol - 2, by = 3)],
                          endorse.out2$s[, seq(from = 1, to = s.ncol - 2, by = 3)],
                          endorse.out3$s[, seq(from = 1, to = s.ncol - 2, by = 3)]))

sample.s.Q2 <- as.mcmc(rbind(endorse.out1$s[, seq(from = 2, to = s.ncol - 1, by = 3)],
                          endorse.out2$s[, seq(from = 2, to = s.ncol - 1, by = 3)],
                          endorse.out3$s[, seq(from = 2, to = s.ncol - 1, by = 3)]))

sample.s.Q3 <- as.mcmc(rbind(endorse.out1$s[, seq(from = 3, to = s.ncol, by = 3)],
                          endorse.out2$s[, seq(from = 3, to = s.ncol, by = 3)],
                          endorse.out3$s[, seq(from = 3, to = s.ncol, by = 3)]))


## extract information
ethnic.indicator.tajik <- endorse.out1$model.matrix.indiv[, "ethno.tribeTajik"]
village.indicator <- endorse.out1$village.indicator
V <- endorse.out1$model.matrix.indiv
village.nums <- sort(unique(as.integer(endorse.out1$village.indicator)))
ethnic.indicator <- V[, "ethno.tribeOther Pashtun"]
ethnic.indicator <- ifelse(ethnic.indicator.tajik == 1, 2, ethnic.indicator)
income.indicator <- V[, "mon_income"]

## to conserve memory
rm(endorse.out2, endorse.out3, endorse.out.list)



###
###
### Table: Summary Statistics for Estimated Posterior Distribution of Model Parameters
###    Table 6 if km.setting == 2
###    Table 8 if km.setting == 5
###
###
library(xtable)
lambda.summary <- summary(sample.lambda[, paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                rep(1:2, each = ncol(endorse.out1$model.matrix.indiv) - 1),
                                                sep = ".")])
lambda.table <- xtable(cbind(lambda.summary$statistics[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                             1, sep = "."), c("Mean", "SD")],
                             lambda.summary$quantiles[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                            1, sep = "."), c("2.5%", "97.5%")],
                             lambda.summary$statistics[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                             2, sep = "."), c("Mean", "SD")],
                             lambda.summary$quantiles[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                            2, sep = "."), c("2.5%", "97.5%")]))
kappa.summary <- summary(sample.kappa[, paste(colnames(endorse.out1$model.matrix.village),
                                              rep(1:2, each = ncol(endorse.out1$model.matrix.village)),
                                              sep = ".")])
kappa.table <- xtable(cbind(kappa.summary$statistics[paste(colnames(endorse.out1$model.matrix.village),
                                                           1, sep = "."), c("Mean", "SD")],
                            kappa.summary$quantiles[paste(colnames(endorse.out1$model.matrix.village),
                                                          1, sep = "."), c("2.5%", "97.5%")],
                            kappa.summary$statistics[paste(colnames(endorse.out1$model.matrix.village),
                                                           2, sep = "."), c("Mean", "SD")],
                            kappa.summary$quantiles[paste(colnames(endorse.out1$model.matrix.village),
                                                          2, sep = "."), c("2.5%", "97.5%")]))
delta.summary <- summary(sample.delta[, colnames(endorse.out1$model.matrix.indiv)[-1]])
delta.table <- xtable(cbind(delta.summary$statistics[, c("Mean", "SD")], delta.summary$quantiles[, c("2.5%", "97.5%")]))
zeta.summary <- summary(sample.zeta[, colnames(endorse.out1$model.matrix.village)])
zeta.table <- xtable(cbind(zeta.summary$statistics[, c("Mean", "SD")], zeta.summary$quantiles[, c("2.5%", "97.5%")]))

indiv.table <- xtable(cbind(lambda.summary$statistics[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                            1, sep = "."), c("Mean")],
                            lambda.summary$quantiles[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                           1, sep = "."), c("2.5%", "97.5%")],
                            lambda.summary$statistics[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                            2, sep = "."), c("Mean")],
                            lambda.summary$quantiles[paste(colnames(endorse.out1$model.matrix.indiv)[-1],
                                                           2, sep = "."), c("2.5%", "97.5%")],
                            delta.summary$statistics[, c("Mean")], delta.summary$quantiles[, c("2.5%", "97.5%")]))
village.table <- xtable(cbind(kappa.summary$statistics[paste(colnames(endorse.out1$model.matrix.village),
                                                             1, sep = "."), c("Mean")],
                              kappa.summary$quantiles[paste(colnames(endorse.out1$model.matrix.village),
                                                            1, sep = "."), c("2.5%", "97.5%")],
                              kappa.summary$statistics[paste(colnames(endorse.out1$model.matrix.village),
                                                             2, sep = "."), c("Mean")],
                              kappa.summary$quantiles[paste(colnames(endorse.out1$model.matrix.village),
                                                            2, sep = "."), c("2.5%", "97.5%")],
                              zeta.summary$statistics[, c("Mean")], zeta.summary$quantiles[, c("2.5%", "97.5%")]))





###
###
### Figure: Estimated Endorsement Effects on Respondents' Support for the GOP Program
###    Figure 4 in the paper if km.setting == 2
###    Figure 15 in the Appendix if km.setting == 5
### 
###
systematic.s.pashtun.1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 1, sep = ".")] %*% t(V[ethnic.indicator.tajik == 0, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 1]))
systematic.s.tajik.1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 1, sep = ".")] %*% t(V[ethnic.indicator.tajik == 1, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 1]))
systematic.s.pashtun.2 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 2, sep = ".")] %*% t(V[ethnic.indicator.tajik == 0, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 2]))
systematic.s.tajik.2 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 2, sep = ".")] %*% t(V[ethnic.indicator.tajik == 1, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 2]))

estimates <- rbind(quantile(apply(pnorm(systematic.s.pashtun.1), 1, mean), prob = c(.025, .5, .975)),
               quantile(apply(pnorm(systematic.s.pashtun.2), 1, mean), prob = c(.025, .5, .975)),               
               quantile(apply(pnorm(systematic.s.pashtun.1), 1, mean) - apply(pnorm(systematic.s.pashtun.2), 1, mean), prob = c(.025, .5, .975)),
               quantile(apply(pnorm(systematic.s.tajik.1), 1, mean), prob = c(.025, .5, .975)),
               quantile(apply(pnorm(systematic.s.tajik.2), 1, mean), prob = c(.025, .5, .975)),               
               quantile(apply(pnorm(systematic.s.tajik.2), 1, mean) - apply(pnorm(systematic.s.tajik.1), 1, mean), prob = c(.025, .5, .975)))
lower.bounds <- estimates[, 1]
point.estimates <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.label <- c("Pashtun\nEndorser", "Tajik\nEndorser", "Coethnic\nBias\n(Pashtun - Tajik)",
                "Pashtun\nEndorser", "Tajik\nEndorser", "Coethnic\nBias\n(Tajik - Pashtun)")
group.label <- c("Pashtun Respondents\n(N=1388)", "Tajik Respondents\n(N=1312)")
plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min
pdf(file = paste("endorseEffects_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 3)
par(oma = c(0, 0, 0, 0))
par(mar = c(2.5, 3.5, 0, 2))
plot.point <- point.estimates
plot.upper <- upper.bounds
plot.lower <- lower.bounds

plot(c(1:(length(plot.point)/2), (length(plot.point)/2 + 2):(length(plot.point) + 1)),
     plot.point,
     xlim = c(.5, length(plot.point) + 1.5),
     ylim = c(0, plot.max + .15 * plot.range),
     main = "",
     ylab = "",
     xlab = "",
     pch = rep(c(20, 22), each = 3),
     axes = FALSE, cex.lab = .8)
for (j in 1:length(plot.point)) {
  lines(c(c(1:(length(plot.point)/2), (length(plot.point)/2 + 2):(length(plot.point) + 1))[j],
          c(1:(length(plot.point)/2), (length(plot.point)/2 + 2):(length(plot.point) + 1))[j]),
        c(plot.lower[j], plot.upper[j]))
}
abline(h = 0, lty = 2)
mtext(plot.label, side = 1, cex = .8, line = c(.5, .5, 1.3),
      at = c(1:(length(plot.point)/2), (length(plot.point)/2 + 2):(length(plot.point) + 1)))
text(c(2, 6), rep(plot.max + .1 * plot.range, times = 2), group.label, cex = .8)
axis(side = 2, at = seq(from = 0, to = .7, by = .1),
     labels = as.character(round(seq(from = 0, to = .7, by = .1), digit = 1)),
     las = 2, cex.axis = .7)
mtext("Estimated Endorsement Effects", side = 2, line = 2.5,
      at = .35, cex = .8)
dev.off()





###
###
### Figure: Estimated Support for the Gardians of Peace Program (Figure 3 in the paper and Figure 14 in the Supplemental Appendix
###    Figure 3 in the paper if km.setting == 2
###    Figure 14 in the Appendix if km.setting == 5
###
###
#### mean of latent response for Pashtun
mean.latent.response.pashtun.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * sample.x[, ethnic.indicator.tajik == 0]
mean.latent.response.pashtun.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * sample.x[, ethnic.indicator.tajik == 0]
mean.latent.response.pashtun.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * sample.x[, ethnic.indicator.tajik == 0]

#### mean of latent response for Pashtun
mean.latent.response.tajik.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * sample.x[, ethnic.indicator.tajik == 1]
mean.latent.response.tajik.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * sample.x[, ethnic.indicator.tajik == 1]
mean.latent.response.tajik.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * sample.x[, ethnic.indicator.tajik == 1]

#### plot for the mean across questions
estimates <- rbind(quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.1) +
                                  pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.2) +
                                  pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.1)
                                  - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.1)) +
                                  (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.2)
                                  - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.2)) +
                                  (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.3)
                                  - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.1)
                                  - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.1)) +
                                  (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.2)
                                  - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.2)) +
                                  (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.3)
                                  - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.1)
                                  - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.1)) +
                                  (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.2)
                                  - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.2)) +
                                  (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.3)
                                  - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.1)) +
                                  (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.2)) +
                                  (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.1) +
                                  pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.2) +
                                  pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.1)
                                  - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.1)) +
                                  (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.2)
                                  - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.2)) +
                                  (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.3)
                                  - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.1)
                                  - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.1)) +
                                  (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.2)
                                  - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.2)) +
                                  (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.3)
                                  - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.1)
                                  - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.1)) +
                                  (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.2)
                                  - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.2)) +
                                  (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.3)
                                  - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.1)) +
                                  (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.2)) +
                                  (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.3))) / 3, 1, mean), prob = c(.025, .5, .975)))

lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min
pdf(file = paste("supportForGOP_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 3)
par(mar = c(0, 3.5, 1, 0))
par(oma = c(0, 0, 0, 0))
x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))
plot(x.temp, plot.points,
     ylim = c(plot.min - .15 * plot.range, plot.max + .1 * plot.range),
     xlim = c(.5, 5.5),
     main = "",
     ylab = "",
     xlab = "",
     pch = rep(c(20, 22), each = 5),
     axes = FALSE, cex.lab = .8)
text(1:5, rep(plot.min - .1 * plot.range, times = 5),
     c("Not", "Unlikely", "Might",
           "Likely", "Certain"), cex = .8)
text(.9, upper.bounds[1], "Pashtun Respondents\n(N=1388)", adj = c(.5, 0), cex = .7)
text(1.1, upper.bounds[6], "Tajik Respondents\n(N=1312)", adj = c(.5, 0), cex = .7)
for(i in 1:10)
  lines(c(x.temp[i], x.temp[i]), c(lower.bounds[i], upper.bounds[i]))
axis(side = 2, at = seq(from = 0, to = .6, by = .1), las = 2, cex.axis = .7)
mtext("Estimated Average\nPredicted Probability", side = 2, at = .3, cex = .8,
      line = 2)
abline(h = 0, lty = 2)
dev.off()



###
###
### Figure: Estimated Effects of Victimization by ISAF on the Magnitude of Coethnic Bias
###    Figure 13 in the Appendix if km.setting == 2
###    Figure 16 in the Appendix if km.setting == 5
###
###
V.noharm.ff <- V
V.noharm.ff[, c("damagebyff.ProTalibanPro-Taliban Pashtun's property damage by ISAF",
                "damagebyff.ProTalibanPro-Taliban Pashtun's harm by ISAF",
                "damagebyff.ProTalibanPro-Taliban Pashtun's both damage by ISAF",
                "damagebyff.OtherOther Pashtun's property damage by ISAF",
                "damagebyff.OtherOther Pashtun's harm by ISAF",
                "damagebyff.OtherOther Pashtun's both damage by ISAF",
                "damagebyff.TajikTajik's property damage by ISAF",
                "damagebyff.TajikTajik's harm by ISAF",
                "damagebyff.TajikTajik's both damage by ISAF")] <- 0
V.both.ff <- V.noharm.ff
V.both.ff[, "damagebyff.ProTalibanPro-Taliban Pashtun's both damage by ISAF"] <- as.integer(ethnic.indicator == 0)
V.both.ff[, "damagebyff.OtherOther Pashtun's both damage by ISAF"] <- as.integer(ethnic.indicator == 1)
V.both.ff[, "damagebyff.TajikTajik's both damage by ISAF"] <- ethnic.indicator.tajik
            
ff.systematic.s.pashtun.noharm.1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 1, sep = ".")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 0, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 1]))
ff.systematic.s.pashtun.both.1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 1, sep = ".")] %*% t(V.both.ff[ethnic.indicator.tajik == 0, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 1]))

ff.systematic.s.tajik.noharm.1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 1, sep = ".")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 1, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 1]))
ff.systematic.s.tajik.both.1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 1, sep = ".")] %*% t(V.both.ff[ethnic.indicator.tajik == 1, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 1]))

ff.systematic.s.pashtun.noharm.2 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 2, sep = ".")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 0, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 2]))
ff.systematic.s.pashtun.both.2 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 2, sep = ".")] %*% t(V.both.ff[ethnic.indicator.tajik == 0, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 2]))

ff.systematic.s.tajik.noharm.2 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 2, sep = ".")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 1, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 2]))
ff.systematic.s.tajik.both.2 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], 2, sep = ".")] %*% t(V.both.ff[ethnic.indicator.tajik == 1, 2:ncol(V)])) / sqrt(as.double(sample.omega2[, 2]))

estimates <- rbind(quantile(apply(pnorm(ff.systematic.s.pashtun.both.1), 1, mean) - apply(pnorm(ff.systematic.s.pashtun.both.2), 1, mean), prob = c(.975, .5, .025)),
                   quantile(apply(pnorm(ff.systematic.s.pashtun.noharm.1), 1, mean) - apply(pnorm(ff.systematic.s.pashtun.noharm.2), 1, mean), prob = c(.975, .5, .025)),
                   quantile((apply(pnorm(ff.systematic.s.pashtun.both.1), 1, mean) - apply(pnorm(ff.systematic.s.pashtun.both.2), 1, mean)) -
                            (apply(pnorm(ff.systematic.s.pashtun.noharm.1), 1, mean) - apply(pnorm(ff.systematic.s.pashtun.noharm.2), 1, mean)), prob = c(.975, .5, .025)),

                   quantile(apply(pnorm(ff.systematic.s.tajik.both.2), 1, mean) - apply(pnorm(ff.systematic.s.tajik.both.1), 1, mean), prob = c(.975, .5, .025)),
                   quantile(apply(pnorm(ff.systematic.s.tajik.noharm.2), 1, mean) - apply(pnorm(ff.systematic.s.tajik.noharm.1), 1, mean), prob = c(.975, .5, .025)),
                   quantile((apply(pnorm(ff.systematic.s.tajik.both.2), 1, mean) - apply(pnorm(ff.systematic.s.tajik.both.1), 1, mean)) -
                            (apply(pnorm(ff.systematic.s.tajik.noharm.2), 1, mean) - apply(pnorm(ff.systematic.s.tajik.noharm.1), 1, mean)), prob = c(.975, .5, .025)))

plot.label <- c("Victimized", "Not\nVictimized", "Difference\n(Victimized\n - Not)")
group.label <- c("Pashtun Respondents' Coethnic Bias: N=1388\n(Pashtun Endorser - Tajik Endorser)",
                 "Tajik Respondents' Coethnic Bias: N=1315\n(Tajik Endorser - Pashtun Endorser)")
pdf(file = paste("effectsVictISAF_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 3)
par(oma = c(0, 0, 0, 0))
par(mar = c(2.5, 3.5, 0.6, 2))

plot.point <- estimates[1:6, 2]
plot.upper <- estimates[1:6, 1]
plot.lower <- estimates[1:6, 3]

plot.max <- max(plot.upper)
plot.min <- min(plot.lower)
plot.range <- plot.max - plot.min

xtemp <- c(1:3, 5:7)

plot(xtemp, plot.point,
     xlim = c(.5, 7.5),
     ylim = c(plot.min, plot.max + .15 * plot.range),
     main = "",
     ylab = "",
     xlab = "",
     pch = rep(c(20, 22), each = 3),
     axes = FALSE, cex.lab = .7)
for (j in 1:6) {
  lines(c(xtemp[j], xtemp[j]), c(plot.lower[j], plot.upper[j]))
}
abline(h = 0, lty = 2)
mtext(group.label, at = c(2, 6), side = 3, cex = .8, line = -1)
mtext(rep(plot.label, 2), side = 1, at = xtemp, cex = .8, line = rep(c(-.3, .5, 1.3), times = 2))
axis(side = 2, at = seq(from = -.2, to = .7, by = .1), labels = seq(from = -.2, to = .7, by = .1),
     las = 2, cex.axis = .7)
mtext("Estimated Coethnic Bias", side = 2, at = .3, cex = .8, line = 2.5)
dev.off()



###
###
### Figure: Estimated Support for the GOP Program by Level of Taliban Control
###    Figure 6 in the Appendix if km.setting == 2
###    Figure 17 in the Appendix if km.setting == 5
###
###
#### comparison between villages under some taliban control and those villages with no taliban (hypothetical)
taliban.nums <- village.nums[endorse.out1$model.matrix.village[, "taliban.control"] == 1]
systematic.policy.taliban <- sample.x[, village.indicator %in% taliban.nums]
##### compute hypothetical villages
village.systematic <- sample.zeta %*% t(endorse.out1$model.matrix.village)
village.random <- sample.delta[, paste("village", 1:100, sep = ".")] - village.systematic
W.0 <- endorse.out1$model.matrix.village
W.0[, "taliban.control"] <- 0
village.notaliban <- sample.zeta %*% t(W.0) + village.random
V.taliban.village <- endorse.out1$model.matrix.indiv[village.indicator %in% taliban.nums, ]
indiv.systematic <- sample.delta[, paste("village", village.indicator[village.indicator %in% taliban.nums], sep = ".")] +
  sample.delta[, colnames(V)[-1]] %*% t(V.taliban.village[, -1])
indiv.random <- sample.x[, village.indicator %in% taliban.nums] - indiv.systematic
systematic.policy.notaliban <- village.notaliban[, village.indicator[village.indicator %in% taliban.nums]] +
  sample.delta[, colnames(V)[-1]] %*% t(V.taliban.village[, -1]) + indiv.random

mean.latent.response.notaliban.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * systematic.policy.notaliban
mean.latent.response.notaliban.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * systematic.policy.notaliban
mean.latent.response.notaliban.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * systematic.policy.notaliban
mean.latent.response.taliban.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * systematic.policy.taliban
mean.latent.response.taliban.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * systematic.policy.taliban
mean.latent.response.taliban.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * systematic.policy.taliban

#### plot for the mean across questions
estimates <- rbind(quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.notaliban.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.notaliban.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.notaliban.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.notaliban.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.notaliban.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.notaliban.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.notaliban.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.notaliban.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.notaliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.notaliban.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.notaliban.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.notaliban.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.notaliban.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.notaliban.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.notaliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.notaliban.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.notaliban.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.notaliban.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.notaliban.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.notaliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1)) +
                                   (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1)) +
                                   (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1))) / 3, 1, mean), prob = c(.025, .5, .975)))

lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min
pdf(file = paste("supportForGOPbyTalibanCtrl_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 3)
par(mar = c(0, 3.5, 1, 0))
par(oma = c(0, 0, 0, 0))
x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))
plot(x.temp, plot.points,
     ylim = c(plot.min - .15 * plot.range, plot.max + .1 * plot.range),
     xlim = c(.5, 5.5),
     main = "",
     ylab = "",
     xlab = "",
     pch = rep(c(17, 25), each = 5),
     axes = FALSE, cex.lab = .8)
text(1:5, rep(plot.min - .1 * plot.range, times = 5),
     c("Not", "Unlikely", "Might", "Likely", "Certain"), cex = .8)
text(.8, .43, "Some\nTaliban\nControl", adj = c(.5, .5), cex = .7)
text(1.3, .59, "No\nTaliban\nControl", adj = c(.5, .5), cex = .7)
for(i in 1:10)
  lines(c(x.temp[i], x.temp[i]), c(lower.bounds[i], upper.bounds[i]))
abline(h = 0, lty = 2)
axis(side = 2, at = seq(from = 0, to = .6, by = .1), las = 2, cex.axis = .7)
mtext("Estimated Average\nPredicted Probability", side = 2, at = .3, cex = .8, line = 2)
dev.off()



###
###
### Figure: Estimated Support for the GOP Program by Level of Contest
###    Figure 8 in the Appendix if km.setting == 2
###    Figure 20 in the Appendix if km.setting == 5
###
###
#### comparison between villages under some taliban control and those villages with no taliban (hypothetical)
taliban.nums <- village.nums[endorse.out1$model.matrix.village[, "contested"] == 1]
systematic.policy.taliban <- sample.x[, village.indicator %in% taliban.nums]
##### compute hypothetical villages
village.systematic <- sample.zeta %*% t(endorse.out1$model.matrix.village)
village.random <- sample.delta[, paste("village", 1:100, sep = ".")] - village.systematic
W.0 <- endorse.out1$model.matrix.village
W.0[, "contested"] <- 0
village.notaliban <- sample.zeta %*% t(W.0) + village.random
V.taliban.village <- endorse.out1$model.matrix.indiv[village.indicator %in% taliban.nums, ]
indiv.systematic <- sample.delta[, paste("village", village.indicator[village.indicator %in% taliban.nums], sep = ".")] +
  sample.delta[, colnames(V)[-1]] %*% t(V.taliban.village[, -1])
indiv.random <- sample.x[, village.indicator %in% taliban.nums] - indiv.systematic
systematic.policy.notaliban <- village.notaliban[, village.indicator[village.indicator %in% taliban.nums]] +
  sample.delta[, colnames(V)[-1]] %*% t(V.taliban.village[, -1]) + indiv.random

mean.latent.response.notaliban.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * systematic.policy.notaliban
mean.latent.response.notaliban.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * systematic.policy.notaliban
mean.latent.response.notaliban.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * systematic.policy.notaliban
mean.latent.response.taliban.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * systematic.policy.taliban
mean.latent.response.taliban.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * systematic.policy.taliban
mean.latent.response.taliban.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * systematic.policy.taliban

#### plot for the mean across questions
estimates <- rbind(quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.notaliban.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.notaliban.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.notaliban.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.notaliban.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.notaliban.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.notaliban.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.notaliban.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.notaliban.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.notaliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.notaliban.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.notaliban.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.notaliban.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.notaliban.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.notaliban.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.notaliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.notaliban.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.notaliban.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.notaliban.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.notaliban.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.notaliban.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1)) +
                                   (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1)) +
                                   (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.notaliban.1))) / 3, 1, mean), prob = c(.025, .5, .975)))

lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min
pdf(file = paste("supportForGOPbyContest_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 3)
par(mar = c(0, 3.5, 1, 0))
par(oma = c(0, 0, 0, 0))
x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))
plot(x.temp, plot.points,
     ylim = c(plot.min - .15 * plot.range, plot.max + .1 * plot.range),
     xlim = c(.5, 5.5),
     main = "",
     ylab = "",
     xlab = "",
     pch = rep(c(17, 25), each = 5),
     axes = FALSE, cex.lab = .8)
text(1:5, rep(plot.min - .1 * plot.range, times = 5),
     c("Not", "Unlikely", "Might", "Likely", "Certain"), cex = .8)
##### labels for quantities ("Highly unlikely" category for each ethnicity)
text(x.temp[1], upper.bounds[1], "Contested\nVillages", adj = c(.5, 0), cex = .7)
text(x.temp[6], lower.bounds[6], "Controled by\nSomeone", adj = c(.5, 1), cex = .7)
for(i in 1:10)
  lines(c(x.temp[i], x.temp[i]), c(lower.bounds[i], upper.bounds[i]))
abline(h = 0, lty = 2)
axis(side = 2, at = seq(from = 0, to = .6, by = .1), las = 2, cex.axis = .7)
mtext("Estimated Average\nPredicted Probability", side = 2, at = .3, cex = .8, line = 2)
dev.off()





###
###
### Figure: Estimated Support for the GOP Program by Victimization and Respondent Ethnicity under ISAF/Pashtun/Tajik conditions
###    Figure 7, 9, and 10 in the Appendix if km.setting == 2
###    Figure 18, 21, and 22 in the Appendix if km.setting == 5
###
###
n.para.delta <- ncol(sample.delta)
ff.systematic.x.pashtun.noharm <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.noharm.ff[ethnic.indicator.tajik == 0, 2:ncol(V)])
ff.systematic.x.pashtun.both <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.both.ff[ethnic.indicator.tajik == 0, 2:ncol(V)])

ff.systematic.x.tajik.noharm <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.noharm.ff[ethnic.indicator.tajik == 1, 2:ncol(V)])
ff.systematic.x.tajik.both <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.both.ff[ethnic.indicator.tajik == 1, 2:ncol(V)])

V.noharm.anp <- V
V.noharm.anp[, c("damagebyanp.ProTalibanPro-Taliban Pashtun's property damage by ANP",
                 "damagebyanp.ProTalibanPro-Taliban Pashtun's harm by ANP",
                 "damagebyanp.ProTalibanPro-Taliban Pashtun's both damage by ANP",
                 "damagebyanp.OtherOther Pashtun's property damage by ANP",
                 "damagebyanp.OtherOther Pashtun's harm by ANP",
                 "damagebyanp.OtherOther Pashtun's both damage by ANP",
                 "damagebyanp.TajikTajik's property damage by ANP",
                 "damagebyanp.TajikTajik's harm by ANP",
                 "damagebyanp.TajikTajik's both damage by ANP")] <- 0
V.both.anp <- V.noharm.anp
V.both.anp[, "damagebyanp.ProTalibanPro-Taliban Pashtun's both damage by ANP"] <- as.integer(ethnic.indicator == 0)
V.both.anp[, "damagebyanp.OtherOther Pashtun's both damage by ANP"] <- as.integer(ethnic.indicator == 1)
V.both.anp[, "damagebyanp.TajikTajik's both damage by ANP"] <- ethnic.indicator.tajik

anp.systematic.x.pashtun.noharm <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.noharm.anp[ethnic.indicator.tajik == 0, 2:ncol(V)])
anp.systematic.x.pashtun.both <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.both.anp[ethnic.indicator.tajik == 0, 2:ncol(V)])

anp.systematic.x.tajik.noharm <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.noharm.anp[ethnic.indicator.tajik == 1, 2:ncol(V)])
anp.systematic.x.tajik.both <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.both.anp[ethnic.indicator.tajik == 1, 2:ncol(V)])

V.noharm.taliban <- V
V.noharm.taliban[, c("damagebytaliban.ProTalibanPro-Taliban Pashtun's harm by Taliban",
                     "damagebytaliban.ProTalibanPro-Taliban Pashtun's both damage by Taliban",
                     "damagebytaliban.OtherOther Pashtun's harm by Taliban",
                     "damagebytaliban.OtherOther Pashtun's both damage by Taliban",
                     "damagebytaliban.TajikTajik's property damage by Taliban",
                     "damagebytaliban.TajikTajik's harm by Taliban",
                     "damagebytaliban.TajikTajik's both damage by Taliban")] <- 0
V.both.taliban <- V.noharm.taliban
V.both.taliban[, "damagebytaliban.ProTalibanPro-Taliban Pashtun's both damage by Taliban"] <- as.integer(ethnic.indicator == 0)
V.both.taliban[, "damagebytaliban.OtherOther Pashtun's both damage by Taliban"] <- as.integer(ethnic.indicator == 1)
V.both.taliban[, "damagebytaliban.TajikTajik's both damage by Taliban"] <- ethnic.indicator.tajik

taliban.systematic.x.pashtun.noharm <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.noharm.taliban[ethnic.indicator.tajik == 0, 2:ncol(V)])
taliban.systematic.x.pashtun.both <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.both.taliban[ethnic.indicator.tajik == 0, 2:ncol(V)])

taliban.systematic.x.tajik.noharm <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.noharm.taliban[ethnic.indicator.tajik == 1, 2:ncol(V)])
taliban.systematic.x.tajik.both <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.both.taliban[ethnic.indicator.tajik == 1, 2:ncol(V)])


##### compute hypothetical individuals
indiv.systematic <- sample.delta[, paste("village", village.indicator, sep = ".")] +
  sample.delta[, colnames(V)[-1]] %*% t(V[, -1])
indiv.random <- sample.x - indiv.systematic

ff.systematic.policy.pashtun.noharm <- ff.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 0] + indiv.random[, ethnic.indicator.tajik == 0 & treat[, 1] == 0]
ff.systematic.policy.pashtun.both <- ff.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 0] + indiv.random[, ethnic.indicator.tajik == 0 & treat[, 1] == 0]
ff.systematic.policy.tajik.noharm <- ff.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 0] + indiv.random[, ethnic.indicator.tajik == 1 & treat[, 1] == 0]
ff.systematic.policy.tajik.both <- ff.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 0]

anp.systematic.policy.pashtun.noharm <- anp.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 0]
anp.systematic.policy.pashtun.both <- anp.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 0]
anp.systematic.policy.tajik.noharm <- anp.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 0]
anp.systematic.policy.tajik.both <- anp.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 0]

taliban.systematic.policy.pashtun.noharm <- taliban.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 0]
taliban.systematic.policy.pashtun.both <- taliban.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 0]
taliban.systematic.policy.tajik.noharm <- taliban.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 0]
taliban.systematic.policy.tajik.both <- taliban.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 0] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 0]


mean.latent.response.ff.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.pashtun.noharm
mean.latent.response.ff.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.pashtun.both
mean.latent.response.ff.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.tajik.noharm
mean.latent.response.ff.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.tajik.both

mean.latent.response.anp.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * anp.systematic.policy.pashtun.noharm
mean.latent.response.anp.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * anp.systematic.policy.pashtun.both
mean.latent.response.anp.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * anp.systematic.policy.tajik.noharm
mean.latent.response.anp.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * anp.systematic.policy.tajik.both

mean.latent.response.taliban.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * taliban.systematic.policy.pashtun.noharm
mean.latent.response.taliban.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * taliban.systematic.policy.pashtun.both
mean.latent.response.taliban.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * taliban.systematic.policy.tajik.noharm
mean.latent.response.taliban.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * taliban.systematic.policy.tajik.both

mean.latent.response.ff.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.pashtun.noharm
mean.latent.response.ff.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.pashtun.both
mean.latent.response.ff.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.tajik.noharm
mean.latent.response.ff.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.tajik.both

mean.latent.response.anp.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * anp.systematic.policy.pashtun.noharm
mean.latent.response.anp.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * anp.systematic.policy.pashtun.both
mean.latent.response.anp.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * anp.systematic.policy.tajik.noharm
mean.latent.response.anp.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * anp.systematic.policy.tajik.both

mean.latent.response.taliban.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * taliban.systematic.policy.pashtun.noharm
mean.latent.response.taliban.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * taliban.systematic.policy.pashtun.both
mean.latent.response.taliban.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * taliban.systematic.policy.tajik.noharm
mean.latent.response.taliban.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * taliban.systematic.policy.tajik.both

mean.latent.response.ff.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.pashtun.noharm
mean.latent.response.ff.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.pashtun.both
mean.latent.response.ff.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.tajik.noharm
mean.latent.response.ff.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.tajik.both

mean.latent.response.anp.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * anp.systematic.policy.pashtun.noharm
mean.latent.response.anp.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * anp.systematic.policy.pashtun.both
mean.latent.response.anp.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * anp.systematic.policy.tajik.noharm
mean.latent.response.anp.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * anp.systematic.policy.tajik.both

mean.latent.response.taliban.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * taliban.systematic.policy.pashtun.noharm
mean.latent.response.taliban.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * taliban.systematic.policy.pashtun.both
mean.latent.response.taliban.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * taliban.systematic.policy.tajik.noharm
mean.latent.response.taliban.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * taliban.systematic.policy.tajik.both

#### plot for the mean across questions
estimates <- rbind(quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),

                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),


                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),

                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)))

lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min

pdf(file = paste("supportForGOPByVictUnderISAF_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 5.1)
par(mfcol = c(2, 2))
par(mar = c(0, 2, 0, 0))
par(oma = c(0, 4, 3, 0))
x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))

for (i in c(1, 3, 4, 6)) {

  plot.temp <- plot.points[(10 * (i - 1) + 1):(10 * i)]
  lower.temp <- lower.bounds[(10 * (i - 1) + 1):(10 * i)]
  upper.temp <- upper.bounds[(10 * (i - 1) + 1):(10 * i)]
  
  plot(x.temp, plot.temp,
       ylim = c(-0.1, plot.max + .1 * plot.range),
       xlim = c(.5, 5.5),
       main = "",
       ylab = "",
       xlab = "",
       pch = rep(c(17, 25), each = 5),
       axes = FALSE, cex.lab = .8, cex = .8)
  text(1:5, rep(-.05, times = 5),
       c("Not", "Unlikely", "Might", "Likely", "Certain"), cex = .8)
  text(x.temp[1], plot.temp[1], "Not", adj = c(1.3, .5), cex = .7)
  text(x.temp[6], plot.temp[6], "Victimized", adj = c(-.1, .5), cex = .7)
  for(i in 1:10)
    lines(c(x.temp[i], x.temp[i]), c(lower.temp[i], upper.temp[i]))
  abline(h = 0, lty = 2)
  axis(side = 2, at = seq(from = 0, to = round(plot.max, digit = 1), by = .1), las = 2,
       cex.axis = .7)
}

mtext("Estimated Average Predicted Probability", side = 2,
      at = .5, cex = .8, line = .5, outer = TRUE)
mtext(c("ISAF Victimization", "Taliban Victimization"), side = 2,
      outer = TRUE, at = c(5/7, 2/7), cex = .8, line = 2.5)
mtext(c("Pashtun Respondents", "Tajik Respondents"), side = 3, outer = TRUE, at = c(.25, .75),
      cex = .8)
mtext("ISAF Endorser Condition", side = 3, outer = TRUE, at = .5, line = 1.5)
dev.off()



##### Willingness to support by violence under Pashtun endorsement
indiv.systematic.s <- sample.lambda[, paste("group", village.indicator[treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V[treat[, 1] == 1, -1])
indiv.random.s.Q1 <- sample.s.Q1[, treat[, 1] == 1] - indiv.systematic.s
indiv.random.s.Q2 <- sample.s.Q2[, treat[, 1] == 1] - indiv.systematic.s
indiv.random.s.Q3 <- sample.s.Q3[, treat[, 1] == 1] - indiv.systematic.s

ff.systematic.s.pashtun.noharm <- sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 0 & treat[, 1] == 1, 2:ncol(V)])
ff.s.pashtun.noharm.Q1 <- ff.systematic.s.pashtun.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
ff.s.pashtun.noharm.Q2 <- ff.systematic.s.pashtun.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
ff.s.pashtun.noharm.Q3 <- ff.systematic.s.pashtun.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]

ff.systematic.s.pashtun.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.both.ff[ethnic.indicator.tajik == 0 & treat[, 1] == 1, 2:ncol(V)]))
ff.s.pashtun.both.Q1 <- ff.systematic.s.pashtun.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
ff.s.pashtun.both.Q2 <- ff.systematic.s.pashtun.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
ff.s.pashtun.both.Q3 <- ff.systematic.s.pashtun.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]

ff.systematic.s.tajik.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 1 & treat[, 1] == 1, 2:ncol(V)]))
ff.s.tajik.noharm.Q1 <- ff.systematic.s.tajik.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
ff.s.tajik.noharm.Q2 <- ff.systematic.s.tajik.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
ff.s.tajik.noharm.Q3 <- ff.systematic.s.tajik.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]

ff.systematic.s.tajik.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.both.ff[ethnic.indicator.tajik == 1 & treat[, 1] == 1, 2:ncol(V)]))
ff.s.tajik.both.Q1 <- ff.systematic.s.tajik.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
ff.s.tajik.both.Q2 <- ff.systematic.s.tajik.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
ff.s.tajik.both.Q3 <- ff.systematic.s.tajik.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]


anp.systematic.s.pashtun.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.noharm.anp[ethnic.indicator.tajik == 0 & treat[, 1] == 1, 2:ncol(V)]))
anp.s.pashtun.noharm.Q1 <- anp.systematic.s.pashtun.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
anp.s.pashtun.noharm.Q2 <- anp.systematic.s.pashtun.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
anp.s.pashtun.noharm.Q3 <- anp.systematic.s.pashtun.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]

anp.systematic.s.pashtun.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.both.anp[ethnic.indicator.tajik == 0 & treat[, 1] == 1, 2:ncol(V)]))
anp.s.pashtun.both.Q1 <- anp.systematic.s.pashtun.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
anp.s.pashtun.both.Q2 <- anp.systematic.s.pashtun.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
anp.s.pashtun.both.Q3 <- anp.systematic.s.pashtun.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]

anp.systematic.s.tajik.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.noharm.anp[ethnic.indicator.tajik == 1 & treat[, 1] == 1, 2:ncol(V)]))
anp.s.tajik.noharm.Q1 <- anp.systematic.s.tajik.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
anp.s.tajik.noharm.Q2 <- anp.systematic.s.tajik.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
anp.s.tajik.noharm.Q3 <- anp.systematic.s.tajik.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]

anp.systematic.s.tajik.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.both.anp[ethnic.indicator.tajik == 1 & treat[, 1] == 1, 2:ncol(V)]))
anp.s.tajik.both.Q1 <- anp.systematic.s.tajik.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
anp.s.tajik.both.Q2 <- anp.systematic.s.tajik.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
anp.s.tajik.both.Q3 <- anp.systematic.s.tajik.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]


taliban.systematic.s.pashtun.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.noharm.taliban[ethnic.indicator.tajik == 0 & treat[, 1] == 1, 2:ncol(V)]))
taliban.s.pashtun.noharm.Q1 <- taliban.systematic.s.pashtun.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
taliban.s.pashtun.noharm.Q2 <- taliban.systematic.s.pashtun.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
taliban.s.pashtun.noharm.Q3 <- taliban.systematic.s.pashtun.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]

taliban.systematic.s.pashtun.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.both.taliban[ethnic.indicator.tajik == 0 & treat[, 1] == 1, 2:ncol(V)]))
taliban.s.pashtun.both.Q1 <- taliban.systematic.s.pashtun.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
taliban.s.pashtun.both.Q2 <- taliban.systematic.s.pashtun.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]
taliban.s.pashtun.both.Q3 <- taliban.systematic.s.pashtun.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 0]

taliban.systematic.s.tajik.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.noharm.taliban[ethnic.indicator.tajik == 1 & treat[, 1] == 1, 2:ncol(V)]))
taliban.s.tajik.noharm.Q1 <- taliban.systematic.s.tajik.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
taliban.s.tajik.noharm.Q2 <- taliban.systematic.s.tajik.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
taliban.s.tajik.noharm.Q3 <- taliban.systematic.s.tajik.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]

taliban.systematic.s.tajik.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.both.taliban[ethnic.indicator.tajik == 1 & treat[, 1] == 1, 2:ncol(V)]))
taliban.s.tajik.both.Q1 <- taliban.systematic.s.tajik.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
taliban.s.tajik.both.Q2 <- taliban.systematic.s.tajik.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]
taliban.s.tajik.both.Q3 <- taliban.systematic.s.tajik.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 1] == 1]

#### construct hypothetical x_i + s_ijk
ff.systematic.policy.pashtun.noharm <- ff.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 1] + indiv.random[, ethnic.indicator.tajik == 0 & treat[, 1] == 1]
ff.systematic.policy.pashtun.both <- ff.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 1] + indiv.random[, ethnic.indicator.tajik == 0 & treat[, 1] == 1]
ff.systematic.policy.tajik.noharm <- ff.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 1] + indiv.random[, ethnic.indicator.tajik == 1 & treat[, 1] == 1]
ff.systematic.policy.tajik.both <- ff.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 1]

anp.systematic.policy.pashtun.noharm <- anp.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 1]
anp.systematic.policy.pashtun.both <- anp.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 1]
anp.systematic.policy.tajik.noharm <- anp.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 1]
anp.systematic.policy.tajik.both <- anp.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 1]

taliban.systematic.policy.pashtun.noharm <- taliban.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 1]
taliban.systematic.policy.pashtun.both <- taliban.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 1]
taliban.systematic.policy.tajik.noharm <- taliban.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 1]
taliban.systematic.policy.tajik.both <- taliban.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 1] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 1]


mean.latent.response.ff.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.pashtun.noharm + ff.s.pashtun.noharm.Q1)
mean.latent.response.ff.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.pashtun.both + ff.s.pashtun.both.Q1)
mean.latent.response.ff.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.tajik.noharm + ff.s.tajik.noharm.Q1)
mean.latent.response.ff.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.tajik.both + ff.s.tajik.both.Q1)

mean.latent.response.anp.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.pashtun.noharm + anp.s.pashtun.noharm.Q1)
mean.latent.response.anp.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.pashtun.both + anp.s.pashtun.both.Q1)
mean.latent.response.anp.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.tajik.noharm + anp.s.tajik.noharm.Q1)
mean.latent.response.anp.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.tajik.both + anp.s.tajik.both.Q1)

mean.latent.response.taliban.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.pashtun.noharm + taliban.s.pashtun.noharm.Q1)
mean.latent.response.taliban.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.pashtun.both + taliban.s.pashtun.both.Q1)
mean.latent.response.taliban.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.tajik.noharm + taliban.s.tajik.noharm.Q1)
mean.latent.response.taliban.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.tajik.both + taliban.s.tajik.both.Q1)

mean.latent.response.ff.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.pashtun.noharm + ff.s.pashtun.noharm.Q2)
mean.latent.response.ff.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.pashtun.both + ff.s.pashtun.both.Q2)
mean.latent.response.ff.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.tajik.noharm + ff.s.tajik.noharm.Q2)
mean.latent.response.ff.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.tajik.both + ff.s.tajik.both.Q2)

mean.latent.response.anp.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.pashtun.noharm + anp.s.pashtun.noharm.Q2)
mean.latent.response.anp.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.pashtun.both + anp.s.pashtun.both.Q2)
mean.latent.response.anp.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.tajik.noharm + anp.s.tajik.noharm.Q2)
mean.latent.response.anp.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.tajik.both + anp.s.tajik.both.Q2)

mean.latent.response.taliban.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.pashtun.noharm + taliban.s.pashtun.noharm.Q2)
mean.latent.response.taliban.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.pashtun.both + taliban.s.pashtun.both.Q2)
mean.latent.response.taliban.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.tajik.noharm + taliban.s.tajik.noharm.Q2)
mean.latent.response.taliban.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.tajik.both + taliban.s.tajik.both.Q2)

mean.latent.response.ff.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.pashtun.noharm + ff.s.pashtun.noharm.Q3)
mean.latent.response.ff.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.pashtun.both + ff.s.pashtun.both.Q3)
mean.latent.response.ff.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.tajik.noharm + ff.s.tajik.noharm.Q3)
mean.latent.response.ff.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.tajik.both + ff.s.tajik.both.Q3)

mean.latent.response.anp.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.pashtun.noharm + anp.s.pashtun.noharm.Q3)
mean.latent.response.anp.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.pashtun.both + anp.s.pashtun.both.Q3)
mean.latent.response.anp.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.tajik.noharm + anp.s.tajik.noharm.Q3)
mean.latent.response.anp.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.tajik.both + anp.s.tajik.both.Q3)

mean.latent.response.taliban.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.pashtun.noharm + taliban.s.pashtun.noharm.Q3)
mean.latent.response.taliban.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.pashtun.both + taliban.s.pashtun.both.Q3)
mean.latent.response.taliban.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.tajik.noharm + taliban.s.tajik.noharm.Q3)
mean.latent.response.taliban.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.tajik.both + taliban.s.tajik.both.Q3)




#### plot for the mean across questions
estimates <- rbind(quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),

                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),


                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),

                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)))



lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min

pdf(file = paste("supportForGOPByVictUnderPashtun_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 5.1)
par(mfcol = c(2, 2))
par(mar = c(0, 2, 0, 0))
par(oma = c(0, 4, 3, 0))
x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))

for (i in c(1, 3, 4, 6)) {

  plot.temp <- plot.points[(10 * (i - 1) + 1):(10 * i)]
  lower.temp <- lower.bounds[(10 * (i - 1) + 1):(10 * i)]
  upper.temp <- upper.bounds[(10 * (i - 1) + 1):(10 * i)]
  
  plot(x.temp, plot.temp,
       ylim = c(-0.1, plot.max + .1 * plot.range),
       xlim = c(.5, 5.5),
       main = "",
       ylab = "",
       xlab = "",
       pch = rep(c(17, 25), each = 5),
       axes = FALSE, cex.lab = .8, cex = .8)
  text(1:5, rep(-.05, times = 5),
       c("Not", "Unlikely", "Might", "Likely", "Certain"), cex = .8)
  text(x.temp[1], plot.temp[1], "Not", adj = c(1.3, .5), cex = .7)
  text(x.temp[6], plot.temp[6], "Victimized", adj = c(-.1, .5), cex = .7)
  for(i in 1:10)
    lines(c(x.temp[i], x.temp[i]), c(lower.temp[i], upper.temp[i]))
  abline(h = 0, lty = 2)
  axis(side = 2, at = seq(from = 0, to = round(plot.max, digit = 1), by = .1), las = 2,
       cex.axis = .7)
}

mtext("Estimated Average Predicted Probability", side = 2,
      at = .5, cex = .8, line = .5, outer = TRUE)
mtext(c("ISAF Victimization", "Taliban Victimization"), side = 2,
      outer = TRUE, at = c(5/7, 2/7), cex = .8, line = 2.5)
mtext(c("Pashtun Respondents", "Tajik Respondents"), side = 3, outer = TRUE, at = c(.25, .75),
      cex = .8)
mtext("Pashtun Endorser Condition", side = 3, at = .5, outer = TRUE, line = 1.5)
dev.off()



##### Willingness to support by violence under Tajik endorsement
indiv.systematic.s <- sample.lambda[, paste("group", village.indicator[treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V[treat[, 1] == 2, -1])
indiv.random.s.Q1 <- sample.s.Q1[, treat[, 1] == 2] - indiv.systematic.s
indiv.random.s.Q2 <- sample.s.Q2[, treat[, 1] == 2] - indiv.systematic.s
indiv.random.s.Q3 <- sample.s.Q3[, treat[, 1] == 2] - indiv.systematic.s


ff.systematic.s.pashtun.noharm <- sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 0 & treat[, 1] == 2, 2:ncol(V)])
ff.s.pashtun.noharm.Q1 <- ff.systematic.s.pashtun.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
ff.s.pashtun.noharm.Q2 <- ff.systematic.s.pashtun.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
ff.s.pashtun.noharm.Q3 <- ff.systematic.s.pashtun.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]

ff.systematic.s.pashtun.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.both.ff[ethnic.indicator.tajik == 0 & treat[, 1] == 2, 2:ncol(V)]))
ff.s.pashtun.both.Q1 <- ff.systematic.s.pashtun.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
ff.s.pashtun.both.Q2 <- ff.systematic.s.pashtun.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
ff.s.pashtun.both.Q3 <- ff.systematic.s.pashtun.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]

ff.systematic.s.tajik.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.noharm.ff[ethnic.indicator.tajik == 1 & treat[, 1] == 2, 2:ncol(V)]))
ff.s.tajik.noharm.Q1 <- ff.systematic.s.tajik.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
ff.s.tajik.noharm.Q2 <- ff.systematic.s.tajik.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
ff.s.tajik.noharm.Q3 <- ff.systematic.s.tajik.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]

ff.systematic.s.tajik.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.both.ff[ethnic.indicator.tajik == 1 & treat[, 1] == 2, 2:ncol(V)]))
ff.s.tajik.both.Q1 <- ff.systematic.s.tajik.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
ff.s.tajik.both.Q2 <- ff.systematic.s.tajik.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
ff.s.tajik.both.Q3 <- ff.systematic.s.tajik.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]


anp.systematic.s.pashtun.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.noharm.anp[ethnic.indicator.tajik == 0 & treat[, 1] == 2, 2:ncol(V)]))
anp.s.pashtun.noharm.Q1 <- anp.systematic.s.pashtun.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
anp.s.pashtun.noharm.Q2 <- anp.systematic.s.pashtun.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
anp.s.pashtun.noharm.Q3 <- anp.systematic.s.pashtun.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]

anp.systematic.s.pashtun.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.both.anp[ethnic.indicator.tajik == 0 & treat[, 1] == 2, 2:ncol(V)]))
anp.s.pashtun.both.Q1 <- anp.systematic.s.pashtun.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
anp.s.pashtun.both.Q2 <- anp.systematic.s.pashtun.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
anp.s.pashtun.both.Q3 <- anp.systematic.s.pashtun.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]

anp.systematic.s.tajik.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.noharm.anp[ethnic.indicator.tajik == 1 & treat[, 1] == 2, 2:ncol(V)]))
anp.s.tajik.noharm.Q1 <- anp.systematic.s.tajik.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
anp.s.tajik.noharm.Q2 <- anp.systematic.s.tajik.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
anp.s.tajik.noharm.Q3 <- anp.systematic.s.tajik.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]

anp.systematic.s.tajik.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.both.anp[ethnic.indicator.tajik == 1 & treat[, 1] == 2, 2:ncol(V)]))
anp.s.tajik.both.Q1 <- anp.systematic.s.tajik.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
anp.s.tajik.both.Q2 <- anp.systematic.s.tajik.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
anp.s.tajik.both.Q3 <- anp.systematic.s.tajik.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]


taliban.systematic.s.pashtun.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.noharm.taliban[ethnic.indicator.tajik == 0 & treat[, 1] == 2, 2:ncol(V)]))
taliban.s.pashtun.noharm.Q1 <- taliban.systematic.s.pashtun.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
taliban.s.pashtun.noharm.Q2 <- taliban.systematic.s.pashtun.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
taliban.s.pashtun.noharm.Q3 <- taliban.systematic.s.pashtun.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]

taliban.systematic.s.pashtun.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.both.taliban[ethnic.indicator.tajik == 0 & treat[, 1] == 2, 2:ncol(V)]))
taliban.s.pashtun.both.Q1 <- taliban.systematic.s.pashtun.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
taliban.s.pashtun.both.Q2 <- taliban.systematic.s.pashtun.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]
taliban.s.pashtun.both.Q3 <- taliban.systematic.s.pashtun.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 0]

taliban.systematic.s.tajik.noharm <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.noharm.taliban[ethnic.indicator.tajik == 1 & treat[, 1] == 2, 2:ncol(V)]))
taliban.s.tajik.noharm.Q1 <- taliban.systematic.s.tajik.noharm + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
taliban.s.tajik.noharm.Q2 <- taliban.systematic.s.tajik.noharm + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
taliban.s.tajik.noharm.Q3 <- taliban.systematic.s.tajik.noharm + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]

taliban.systematic.s.tajik.both <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & treat[, 1] == 2], ".", 2, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 2, sep = "")] %*% t(V.both.taliban[ethnic.indicator.tajik == 1 & treat[, 1] == 2, 2:ncol(V)]))
taliban.s.tajik.both.Q1 <- taliban.systematic.s.tajik.both + indiv.random.s.Q1[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
taliban.s.tajik.both.Q2 <- taliban.systematic.s.tajik.both + indiv.random.s.Q2[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]
taliban.s.tajik.both.Q3 <- taliban.systematic.s.tajik.both + indiv.random.s.Q3[, ethnic.indicator.tajik[treat[, 1] == 2] == 1]

#### construct hypothetical x_i + s_ijk
ff.systematic.policy.pashtun.noharm <- ff.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 2] + indiv.random[, ethnic.indicator.tajik == 0 & treat[, 1] == 2]
ff.systematic.policy.pashtun.both <- ff.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 2] + indiv.random[, ethnic.indicator.tajik == 0 & treat[, 1] == 2]
ff.systematic.policy.tajik.noharm <- ff.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 2] + indiv.random[, ethnic.indicator.tajik == 1 & treat[, 1] == 2]
ff.systematic.policy.tajik.both <- ff.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 2]

anp.systematic.policy.pashtun.noharm <- anp.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 2]
anp.systematic.policy.pashtun.both <- anp.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 2]
anp.systematic.policy.tajik.noharm <- anp.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 2]
anp.systematic.policy.tajik.both <- anp.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 2]

taliban.systematic.policy.pashtun.noharm <- taliban.systematic.x.pashtun.noharm[, treat[ethnic.indicator.tajik == 0, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 2]
taliban.systematic.policy.pashtun.both <- taliban.systematic.x.pashtun.both[, treat[ethnic.indicator.tajik == 0, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 0 & treat[, 1] == 2]
taliban.systematic.policy.tajik.noharm <- taliban.systematic.x.tajik.noharm[, treat[ethnic.indicator.tajik == 1, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 2]
taliban.systematic.policy.tajik.both <- taliban.systematic.x.tajik.both[, treat[ethnic.indicator.tajik == 1, 1] == 2] + indiv.random[,ethnic.indicator.tajik == 1 & treat[, 1] == 2]


mean.latent.response.ff.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.pashtun.noharm + ff.s.pashtun.noharm.Q1)
mean.latent.response.ff.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.pashtun.both + ff.s.pashtun.both.Q1)
mean.latent.response.ff.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.tajik.noharm + ff.s.tajik.noharm.Q1)
mean.latent.response.ff.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (ff.systematic.policy.tajik.both + ff.s.tajik.both.Q1)

mean.latent.response.anp.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.pashtun.noharm + anp.s.pashtun.noharm.Q1)
mean.latent.response.anp.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.pashtun.both + anp.s.pashtun.both.Q1)
mean.latent.response.anp.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.tajik.noharm + anp.s.tajik.noharm.Q1)
mean.latent.response.anp.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (anp.systematic.policy.tajik.both + anp.s.tajik.both.Q1)

mean.latent.response.taliban.pashtun.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.pashtun.noharm + taliban.s.pashtun.noharm.Q1)
mean.latent.response.taliban.pashtun.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.pashtun.both + taliban.s.pashtun.both.Q1)
mean.latent.response.taliban.tajik.noharm.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.tajik.noharm + taliban.s.tajik.noharm.Q1)
mean.latent.response.taliban.tajik.both.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (taliban.systematic.policy.tajik.both + taliban.s.tajik.both.Q1)

mean.latent.response.ff.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.pashtun.noharm + ff.s.pashtun.noharm.Q2)
mean.latent.response.ff.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.pashtun.both + ff.s.pashtun.both.Q2)
mean.latent.response.ff.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.tajik.noharm + ff.s.tajik.noharm.Q2)
mean.latent.response.ff.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (ff.systematic.policy.tajik.both + ff.s.tajik.both.Q2)

mean.latent.response.anp.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.pashtun.noharm + anp.s.pashtun.noharm.Q2)
mean.latent.response.anp.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.pashtun.both + anp.s.pashtun.both.Q2)
mean.latent.response.anp.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.tajik.noharm + anp.s.tajik.noharm.Q2)
mean.latent.response.anp.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (anp.systematic.policy.tajik.both + anp.s.tajik.both.Q2)

mean.latent.response.taliban.pashtun.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.pashtun.noharm + taliban.s.pashtun.noharm.Q2)
mean.latent.response.taliban.pashtun.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.pashtun.both + taliban.s.pashtun.both.Q2)
mean.latent.response.taliban.tajik.noharm.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.tajik.noharm + taliban.s.tajik.noharm.Q2)
mean.latent.response.taliban.tajik.both.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (taliban.systematic.policy.tajik.both + taliban.s.tajik.both.Q2)

mean.latent.response.ff.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.pashtun.noharm + ff.s.pashtun.noharm.Q3)
mean.latent.response.ff.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.pashtun.both + ff.s.pashtun.both.Q3)
mean.latent.response.ff.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.tajik.noharm + ff.s.tajik.noharm.Q3)
mean.latent.response.ff.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (ff.systematic.policy.tajik.both + ff.s.tajik.both.Q3)

mean.latent.response.anp.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.pashtun.noharm + anp.s.pashtun.noharm.Q3)
mean.latent.response.anp.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.pashtun.both + anp.s.pashtun.both.Q3)
mean.latent.response.anp.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.tajik.noharm + anp.s.tajik.noharm.Q3)
mean.latent.response.anp.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (anp.systematic.policy.tajik.both + anp.s.tajik.both.Q3)

mean.latent.response.taliban.pashtun.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.pashtun.noharm + taliban.s.pashtun.noharm.Q3)
mean.latent.response.taliban.pashtun.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.pashtun.both + taliban.s.pashtun.both.Q3)
mean.latent.response.taliban.tajik.noharm.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.tajik.noharm + taliban.s.tajik.noharm.Q3)
mean.latent.response.taliban.tajik.both.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (taliban.systematic.policy.tajik.both + taliban.s.tajik.both.Q3)




#### plot for the mean across questions
estimates <- rbind(quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),

                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.pashtun.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.pashtun.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.pashtun.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),


                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.anp.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.anp.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.anp.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),

                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.noharm.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.noharm.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.noharm.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.noharm.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.noharm.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.noharm.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.noharm.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.noharm.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.noharm.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.both.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.both.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.both.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.both.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.both.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.both.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.taliban.tajik.both.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.taliban.tajik.both.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.taliban.tajik.both.3))) / 3, 1, mean), prob = c(.025, .5, .975)))



lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min

pdf(file = paste("supportForGOPByVictUnderTajik_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 5.1)
par(mfcol = c(2, 2))
par(mar = c(0, 2, 0, 0))
par(oma = c(0, 4, 3, 0))

x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))

for (i in c(1,3,4,6)) {

  plot.temp <- plot.points[(10 * (i - 1) + 1):(10 * i)]
  lower.temp <- lower.bounds[(10 * (i - 1) + 1):(10 * i)]
  upper.temp <- upper.bounds[(10 * (i - 1) + 1):(10 * i)]
  
  plot(x.temp, plot.temp,
       ylim = c(-0.1, plot.max + .1 * plot.range),
       xlim = c(.5, 5.5),
       main = "",
       ylab = "",
       xlab = "",
       pch = rep(c(17, 25), each = 5),
       axes = FALSE, cex.lab = .8, cex = .8)
  text(1:5, rep(-.05, times = 5),
       c("Not", "Unlikely", "Might", "Likely", "Certain"), cex = .8)
  text(x.temp[1], plot.temp[1], "Not", adj = c(1.3, .5), cex = .7)
  text(x.temp[6], plot.temp[6], "Victimized", adj = c(-.1, .5), cex = .7)
  for(i in 1:10)
    lines(c(x.temp[i], x.temp[i]), c(lower.temp[i], upper.temp[i]))
  abline(h = 0, lty = 2)
  axis(side = 2, at = seq(from = 0, to = round(plot.max, digit = 1), by = .1), las = 2,
       cex.axis = .7)
}

mtext("Estimated Average Predicted Probability", side = 2,
      at = .5, cex = .8, line = .5, outer = TRUE)
mtext(c("ISAF Victimization", "Taliban Victimization"), side = 2,
      outer = TRUE, at = c(5/7, 2/7), cex = .8, line = 2.5)
mtext(c("Pashtun Respondents", "Tajik Respondents"), side = 3, outer = TRUE, at = c(.25, .75),
      cex = .8)
mtext("Tajik Endorser Condition", side = 3, at = .5, outer = TRUE, line = 1.5)
dev.off()




###
###
### Figure: Willingness to Inform by monthly income and Respondent Ethnicity under ISAF/Pashtun/Tajik conditions
###    Figure 12 in the Appendix if km.setting == 2
###    Figure 23 in the Appendix if km.setting == 5
###
###
n.para.delta <- ncol(sample.delta)
ff.systematic.x.pashtun.in3 <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0 & income.indicator == 3], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V[ethnic.indicator.tajik == 0 & income.indicator == 3, 2:ncol(V)])
ff.systematic.x.tajik.in3 <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1 & income.indicator == 3], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V[ethnic.indicator.tajik == 1 & income.indicator == 3, 2:ncol(V)])

V.income1 <- V
V.income1[, "mon_income"] <- 1
ff.systematic.x.pashtun.in1 <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 0 & income.indicator == 3], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.income1[ethnic.indicator.tajik == 0 & income.indicator == 3, 2:ncol(V)])
ff.systematic.x.tajik.in1 <- sample.delta[, paste("village", village.indicator[ethnic.indicator.tajik == 1 & income.indicator == 3], sep = ".")] +
  sample.delta[, 101:n.para.delta] %*% t(V.income1[ethnic.indicator.tajik == 1 & income.indicator == 3, 2:ncol(V)])

##### compute hypothetical individuals under ISAF endorser
indiv.systematic <- sample.delta[, paste("village", village.indicator, sep = ".")] +
  sample.delta[, colnames(V)[-1]] %*% t(V[, -1])
indiv.random <- sample.x - indiv.systematic
ff.systematic.policy.pashtun.in1 <- ff.systematic.x.pashtun.in1[, treat[ethnic.indicator.tajik == 0 & income.indicator == 3, 1] == 0] + indiv.random[, ethnic.indicator.tajik == 0  & income.indicator == 3 & treat[, 1] == 0]
ff.systematic.policy.pashtun.in3 <- ff.systematic.x.pashtun.in3[, treat[ethnic.indicator.tajik == 0 & income.indicator == 3, 1] == 0] + indiv.random[, ethnic.indicator.tajik == 0 & income.indicator == 3 & treat[, 1] == 0]
ff.systematic.policy.tajik.in1 <- ff.systematic.x.tajik.in1[, treat[ethnic.indicator.tajik == 1 & income.indicator == 3, 1] == 0] + indiv.random[, ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 0]
ff.systematic.policy.tajik.in3 <- ff.systematic.x.tajik.in3[, treat[ethnic.indicator.tajik == 1 & income.indicator == 3, 1] == 0] + indiv.random[, ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 0]

mean.latent.response.ff.pashtun.in1.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.pashtun.in1
mean.latent.response.ff.pashtun.in3.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.pashtun.in3
mean.latent.response.ff.tajik.in1.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.tajik.in1
mean.latent.response.ff.tajik.in3.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * ff.systematic.policy.tajik.in3

mean.latent.response.ff.pashtun.in1.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.pashtun.in1
mean.latent.response.ff.pashtun.in3.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.pashtun.in3
mean.latent.response.ff.tajik.in1.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.tajik.in1
mean.latent.response.ff.tajik.in3.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * ff.systematic.policy.tajik.in3

mean.latent.response.ff.pashtun.in1.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.pashtun.in1
mean.latent.response.ff.pashtun.in3.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.pashtun.in3
mean.latent.response.ff.tajik.in1.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.tajik.in1
mean.latent.response.ff.tajik.in3.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * ff.systematic.policy.tajik.in3



##### Willingness to support by violence under Pashtun endorsement
pashtun.systematic.policy.pashtun.in1 <- ff.systematic.x.pashtun.in1[, treat[ethnic.indicator.tajik == 0 & income.indicator == 3, 1] == 1] + indiv.random[, ethnic.indicator.tajik == 0  & income.indicator == 3 & treat[, 1] == 1]
pashtun.systematic.policy.pashtun.in3 <- ff.systematic.x.pashtun.in3[, treat[ethnic.indicator.tajik == 0 & income.indicator == 3, 1] == 1] + indiv.random[, ethnic.indicator.tajik == 0 & income.indicator == 3 & treat[, 1] == 1]
pashtun.systematic.policy.tajik.in1 <- ff.systematic.x.tajik.in1[, treat[ethnic.indicator.tajik == 1 & income.indicator == 3, 1] == 1] + indiv.random[, ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 1]
pashtun.systematic.policy.tajik.in3 <- ff.systematic.x.tajik.in3[, treat[ethnic.indicator.tajik == 1 & income.indicator == 3, 1] == 1] + indiv.random[, ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 1]

indiv.systematic.s <- sample.lambda[, paste("group", village.indicator[treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V[treat[, 1] == 1, -1])
indiv.random.s.Q1 <- sample.s.Q1[, treat[, 1] == 1] - indiv.systematic.s
indiv.random.s.Q2 <- sample.s.Q2[, treat[, 1] == 1] - indiv.systematic.s
indiv.random.s.Q3 <- sample.s.Q3[, treat[, 1] == 1] - indiv.systematic.s

pashtun.systematic.s.pashtun.in1 <- sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0  & income.indicator == 3 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.income1[ethnic.indicator.tajik == 0  & income.indicator == 3 & treat[, 1] == 1, 2:ncol(V)])
pashtun.s.pashtun.in1.Q1 <- pashtun.systematic.s.pashtun.in1 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 0]
pashtun.s.pashtun.in1.Q2 <- pashtun.systematic.s.pashtun.in1 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 0]
pashtun.s.pashtun.in1.Q3 <- pashtun.systematic.s.pashtun.in1 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 0]

pashtun.systematic.s.pashtun.in3 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & income.indicator == 3 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V[ethnic.indicator.tajik == 0 & income.indicator == 3 & treat[, 1] == 1, 2:ncol(V)]))
pashtun.s.pashtun.in3.Q1 <- pashtun.systematic.s.pashtun.in3 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 0]
pashtun.s.pashtun.in3.Q2 <- pashtun.systematic.s.pashtun.in3 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 0]
pashtun.s.pashtun.in3.Q3 <- pashtun.systematic.s.pashtun.in3 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 0]

pashtun.systematic.s.tajik.in1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.income1[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 1, 2:ncol(V)]))
pashtun.s.tajik.in1.Q1 <- pashtun.systematic.s.tajik.in1 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 1]
pashtun.s.tajik.in1.Q2 <- pashtun.systematic.s.tajik.in1 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 1]
pashtun.s.tajik.in1.Q3 <- pashtun.systematic.s.tajik.in1 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 1]

pashtun.systematic.s.tajik.in3 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 1], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 1, 2:ncol(V)]))
pashtun.s.tajik.in3.Q1 <- pashtun.systematic.s.tajik.in3 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 1]
pashtun.s.tajik.in3.Q2 <- pashtun.systematic.s.tajik.in3 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 1]
pashtun.s.tajik.in3.Q3 <- pashtun.systematic.s.tajik.in3 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 1] == 3 & ethnic.indicator.tajik[treat[, 1] == 1] == 1]

mean.latent.response.pashtun.pashtun.in1.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (pashtun.systematic.policy.pashtun.in1 + pashtun.s.pashtun.in1.Q1)
mean.latent.response.pashtun.pashtun.in3.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (pashtun.systematic.policy.pashtun.in3 + pashtun.s.pashtun.in3.Q1)
mean.latent.response.pashtun.tajik.in1.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (pashtun.systematic.policy.tajik.in1 + pashtun.s.tajik.in1.Q1)
mean.latent.response.pashtun.tajik.in3.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (pashtun.systematic.policy.tajik.in3 + pashtun.s.tajik.in3.Q1)

mean.latent.response.pashtun.pashtun.in1.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (pashtun.systematic.policy.pashtun.in1 + pashtun.s.pashtun.in1.Q2)
mean.latent.response.pashtun.pashtun.in3.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (pashtun.systematic.policy.pashtun.in3 + pashtun.s.pashtun.in3.Q2)
mean.latent.response.pashtun.tajik.in1.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (pashtun.systematic.policy.tajik.in1 + pashtun.s.tajik.in1.Q2)
mean.latent.response.pashtun.tajik.in3.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (pashtun.systematic.policy.tajik.in3 + pashtun.s.tajik.in3.Q2)

mean.latent.response.pashtun.pashtun.in1.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (pashtun.systematic.policy.pashtun.in1 + pashtun.s.pashtun.in1.Q3)
mean.latent.response.pashtun.pashtun.in3.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (pashtun.systematic.policy.pashtun.in3 + pashtun.s.pashtun.in3.Q3)
mean.latent.response.pashtun.tajik.in1.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (pashtun.systematic.policy.tajik.in1 + pashtun.s.tajik.in1.Q3)
mean.latent.response.pashtun.tajik.in3.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (pashtun.systematic.policy.tajik.in3 + pashtun.s.tajik.in3.Q3)


##### Willingness to support by violence under Tajik endorsement
tajik.systematic.policy.pashtun.in1 <- ff.systematic.x.pashtun.in1[, treat[ethnic.indicator.tajik == 0 & income.indicator == 3, 1] == 2] + indiv.random[, ethnic.indicator.tajik == 0  & income.indicator == 3 & treat[, 1] == 2]
tajik.systematic.policy.pashtun.in3 <- ff.systematic.x.pashtun.in3[, treat[ethnic.indicator.tajik == 0 & income.indicator == 3, 1] == 2] + indiv.random[, ethnic.indicator.tajik == 0 & income.indicator == 3 & treat[, 1] == 2]
tajik.systematic.policy.tajik.in1 <- ff.systematic.x.tajik.in1[, treat[ethnic.indicator.tajik == 1 & income.indicator == 3, 1] == 2] + indiv.random[, ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 2]
tajik.systematic.policy.tajik.in3 <- ff.systematic.x.tajik.in3[, treat[ethnic.indicator.tajik == 1 & income.indicator == 3, 1] == 2] + indiv.random[, ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 2]

indiv.systematic.s <- sample.lambda[, paste("group", village.indicator[treat[, 1] == 2], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V[treat[, 1] == 2, -1])
indiv.random.s.Q1 <- sample.s.Q1[, treat[, 1] == 2] - indiv.systematic.s
indiv.random.s.Q2 <- sample.s.Q2[, treat[, 1] == 2] - indiv.systematic.s
indiv.random.s.Q3 <- sample.s.Q3[, treat[, 1] == 2] - indiv.systematic.s

tajik.systematic.s.pashtun.in1 <- sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0  & income.indicator == 3 & treat[, 1] == 2], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.income1[ethnic.indicator.tajik == 0  & income.indicator == 3 & treat[, 1] == 2, 2:ncol(V)])
tajik.s.pashtun.in1.Q1 <- tajik.systematic.s.pashtun.in1 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 0]
tajik.s.pashtun.in1.Q2 <- tajik.systematic.s.pashtun.in1 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 0]
tajik.s.pashtun.in1.Q3 <- tajik.systematic.s.pashtun.in1 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 0]

tajik.systematic.s.pashtun.in3 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 0 & income.indicator == 3 & treat[, 1] == 2], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V[ethnic.indicator.tajik == 0 & income.indicator == 3 & treat[, 1] == 2, 2:ncol(V)]))
tajik.s.pashtun.in3.Q1 <- tajik.systematic.s.pashtun.in3 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 0]
tajik.s.pashtun.in3.Q2 <- tajik.systematic.s.pashtun.in3 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 0]
tajik.s.pashtun.in3.Q3 <- tajik.systematic.s.pashtun.in3 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 0]

tajik.systematic.s.tajik.in1 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 2], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V.income1[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 2, 2:ncol(V)]))
tajik.s.tajik.in1.Q1 <- tajik.systematic.s.tajik.in1 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 1]
tajik.s.tajik.in1.Q2 <- tajik.systematic.s.tajik.in1 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 1]
tajik.s.tajik.in1.Q3 <- tajik.systematic.s.tajik.in1 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 1]

tajik.systematic.s.tajik.in3 <- (sample.lambda[, paste("group", village.indicator[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 2], ".", 1, sep = "")] +
  sample.lambda[, paste(colnames(V)[-1], ".", 1, sep = "")] %*% t(V[ethnic.indicator.tajik == 1 & income.indicator == 3 & treat[, 1] == 2, 2:ncol(V)]))
tajik.s.tajik.in3.Q1 <- tajik.systematic.s.tajik.in3 + indiv.random.s.Q1[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 1]
tajik.s.tajik.in3.Q2 <- tajik.systematic.s.tajik.in3 + indiv.random.s.Q2[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 1]
tajik.s.tajik.in3.Q3 <- tajik.systematic.s.tajik.in3 + indiv.random.s.Q3[, income.indicator[treat[, 1] == 2] == 3 & ethnic.indicator.tajik[treat[, 1] == 2] == 1]

mean.latent.response.tajik.pashtun.in1.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (tajik.systematic.policy.pashtun.in1 + tajik.s.pashtun.in1.Q1)
mean.latent.response.tajik.pashtun.in3.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (tajik.systematic.policy.pashtun.in3 + tajik.s.pashtun.in3.Q1)
mean.latent.response.tajik.tajik.in1.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (tajik.systematic.policy.tajik.in1 + tajik.s.tajik.in1.Q1)
mean.latent.response.tajik.tajik.in3.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * (tajik.systematic.policy.tajik.in3 + tajik.s.tajik.in3.Q1)

mean.latent.response.tajik.pashtun.in1.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (tajik.systematic.policy.pashtun.in1 + tajik.s.pashtun.in1.Q2)
mean.latent.response.tajik.pashtun.in3.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (tajik.systematic.policy.pashtun.in3 + tajik.s.pashtun.in3.Q2)
mean.latent.response.tajik.tajik.in1.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (tajik.systematic.policy.tajik.in1 + tajik.s.tajik.in1.Q2)
mean.latent.response.tajik.tajik.in3.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * (tajik.systematic.policy.tajik.in3 + tajik.s.tajik.in3.Q2)

mean.latent.response.tajik.pashtun.in1.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (tajik.systematic.policy.pashtun.in1 + tajik.s.pashtun.in1.Q3)
mean.latent.response.tajik.pashtun.in3.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (tajik.systematic.policy.pashtun.in3 + tajik.s.pashtun.in3.Q3)
mean.latent.response.tajik.tajik.in1.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (tajik.systematic.policy.tajik.in1 + tajik.s.tajik.in1.Q3)
mean.latent.response.tajik.tajik.in3.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * (tajik.systematic.policy.tajik.in3 + tajik.s.tajik.in3.Q3)




#### plot for the mean across questions
estimates <- rbind(### ISAF endorser, pashtun respondent
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.in1.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.in1.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.in1.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.in1.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.in1.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.in3.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.in3.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.in3.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.pashtun.in3.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.pashtun.in3.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   ### ISAF endorser, tajik respondent
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.in1.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.in1.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.in1.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.in1.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.in1.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.in3.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.in3.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.in3.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.ff.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.ff.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.ff.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.ff.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.ff.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.ff.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.ff.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.ff.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.ff.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.ff.tajik.in3.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.ff.tajik.in3.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.ff.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   ### pashtun endorser, pashtun respondent
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.pashtun.in1.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.pashtun.in1.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.pashtun.in1.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.pashtun.in1.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.pashtun.in1.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.pashtun.in3.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.pashtun.in3.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.pashtun.in3.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.pashtun.in3.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.pashtun.in3.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   ### pashtun endorser, tajik respondent
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.tajik.in1.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.tajik.in1.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.tajik.in1.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.tajik.in1.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.tajik.in1.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.tajik.in3.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.tajik.in3.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.tajik.in3.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.pashtun.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.pashtun.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.pashtun.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.pashtun.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.pashtun.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.pashtun.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.pashtun.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.pashtun.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.pashtun.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.pashtun.tajik.in3.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.pashtun.tajik.in3.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.pashtun.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   ### tajik endorser, pashtun respondent
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.pashtun.in1.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.pashtun.in1.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.pashtun.in1.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.pashtun.in1.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.pashtun.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.pashtun.in1.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.pashtun.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.pashtun.in1.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.pashtun.in1.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.pashtun.in1.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.pashtun.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.pashtun.in3.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.pashtun.in3.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.pashtun.in3.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.pashtun.in3.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.pashtun.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.pashtun.in3.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.pashtun.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.pashtun.in3.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.pashtun.in3.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.pashtun.in3.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.pashtun.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   ### tajik endorser, tajik respondent
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.tajik.in1.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.tajik.in1.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.tajik.in1.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.tajik.in1.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.tajik.in1.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.tajik.in1.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.tajik.in1.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.tajik.in1.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.tajik.in1.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.tajik.in1.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.tajik.in1.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.tajik.in3.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.tajik.in3.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.tajik.in3.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.tajik.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.tajik.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.tajik.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.tajik.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.tajik.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.tajik.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.tajik.in3.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.tajik.tajik.in3.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.tajik.in3.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.tajik.tajik.in3.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.tajik.in3.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.tajik.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.tajik.tajik.in3.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.tajik.tajik.in3.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.tajik.tajik.in3.3))) / 3, 1, mean), prob = c(.025, .5, .975)))

lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min

pdf(file = paste("supportForGOPByIncome_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 5.1)
par(mfrow = c(3, 2))
par(mar = c(0, 2, 0, 0))
par(oma = c(0, 4, 2, 0))
x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))

for (i in 1:6) {

  plot.temp <- plot.points[(10 * (i - 1) + 1):(10 * i)]
  lower.temp <- lower.bounds[(10 * (i - 1) + 1):(10 * i)]
  upper.temp <- upper.bounds[(10 * (i - 1) + 1):(10 * i)]
  
  plot(x.temp, plot.temp,
       ylim = c(-0.1, plot.max + .1 * plot.range),
       xlim = c(.5, 5.5),
       main = "",
       ylab = "",
       xlab = "",
       pch = rep(c(17, 25), each = 5),
       axes = FALSE, cex.lab = .8, cex = .8)
  text(1:5, rep(-.05, times = 5),
       c("Not", "Unlikely", "Might", "Likely", "Certain"), cex = .8)
  text(x.temp[1], upper.temp[1], "< 2000", adj = c(.5, 0), cex = .7)
  text(x.temp[6], plot.temp[6], "10001\n-20000", adj = c(-.1, .5), cex = .7)
  for(i in 1:10)
    lines(c(x.temp[i], x.temp[i]), c(lower.temp[i], upper.temp[i]))
  abline(h = 0, lty = 2)
  axis(side = 2, at = seq(from = 0, to = round(plot.max, digit = 1), by = .1), las = 2,
       cex.axis = .7)
}

mtext("Estimated Average Predicted Probability", side = 2,
      at = .5, cex = .8, line = .5, outer = TRUE)
mtext(c("Pashtun Respondents", "Tajik Respondents"), side = 3, outer = TRUE, at = c(.25, .75),
      cex = .8)
mtext(c("ISAF Endorser", "Pashtun Endorser", "Tajik Endorser"), side = 2, outer = TRUE, at = c(.85, .5, .15), line = 2.5, cex = .8)
dev.off()






###
###
### Figure: Estimated Willingness to Infrom by Existence of Aid Site
###    Figure 11 in the Appendix if km.setting == 2
###    Figure 19 in the Appendix if km.setting == 5
###    
###

#### comparison between villages under some taliban control and those villages with no taliban (hypothetical)
nsp.nums <- village.nums[endorse.out1$model.matrix.village[, "nsp.0"] == 1]
systematic.policy.nsp <- sample.x[, village.indicator %in% nsp.nums]
##### compute hypothetical villages
village.systematic <- sample.zeta %*% t(endorse.out1$model.matrix.village)
village.random <- sample.delta[, paste("village", 1:100, sep = ".")] - village.systematic
W.0 <- endorse.out1$model.matrix.village
W.0[, "nsp.0"] <- 0
village.nonsp <- sample.zeta %*% t(W.0) + village.random
V.nsp <- endorse.out1$model.matrix.indiv[village.indicator %in% nsp.nums, ]
indiv.systematic <- sample.delta[, paste("village", village.indicator[village.indicator %in% nsp.nums], sep = ".")] +
  sample.delta[, colnames(V)[-1]] %*% t(V.nsp[, -1])
indiv.random <- sample.x[, village.indicator %in% nsp.nums] - indiv.systematic
systematic.policy.nonsp <- village.nonsp[, village.indicator[village.indicator %in% nsp.nums]] +
  sample.delta[, colnames(V)[-1]] %*% t(V.nsp[, -1]) + indiv.random

mean.latent.response.nonsp.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * systematic.policy.nonsp
mean.latent.response.nonsp.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * systematic.policy.nonsp
mean.latent.response.nonsp.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * systematic.policy.nonsp
mean.latent.response.nsp.1 <- - sample.beta[, "alpha.1"] + sample.beta[, "beta.1"] * systematic.policy.nsp
mean.latent.response.nsp.2 <- - sample.beta[, "alpha.2"] + sample.beta[, "beta.2"] * systematic.policy.nsp
mean.latent.response.nsp.3 <- - sample.beta[, "alpha.3"] + sample.beta[, "beta.3"] * systematic.policy.nsp

#### plot for the mean across questions
estimates <- rbind(quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.nsp.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.nsp.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.nsp.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.nsp.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.nsp.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.nsp.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.nsp.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.nsp.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.nsp.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.nsp.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.nsp.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.nsp.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.nsp.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.nsp.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.nsp.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.nsp.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.nsp.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.nsp.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.nsp.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.nsp.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.nsp.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.nsp.1)) +
                                   (1 - pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.nsp.2)) +
                                   (1 - pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.nsp.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply((pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.nonsp.1) +
                                   pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.nonsp.2) +
                                   pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.nonsp.3)) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.nonsp.1)
                                    - pnorm(sample.tau[, "tau1.1"], mean = mean.latent.response.nonsp.1)) +
                                   (pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.nonsp.2)
                                    - pnorm(sample.tau[, "tau2.1"], mean = mean.latent.response.nonsp.2)) +
                                   (pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.nonsp.3)
                                    - pnorm(sample.tau[, "tau3.1"], mean = mean.latent.response.nonsp.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.nonsp.1)
                                    - pnorm(sample.tau[, "tau1.2"], mean = mean.latent.response.nonsp.1)) +
                                   (pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.nonsp.2)
                                    - pnorm(sample.tau[, "tau2.2"], mean = mean.latent.response.nonsp.2)) +
                                   (pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.nonsp.3)
                                    - pnorm(sample.tau[, "tau3.2"], mean = mean.latent.response.nonsp.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.nonsp.1)
                                    - pnorm(sample.tau[, "tau1.3"], mean = mean.latent.response.nonsp.1)) +
                                   (pnorm(sample.tau[, "tau2.4"], mean = mean.latent.response.nonsp.2)
                                    - pnorm(sample.tau[, "tau2.3"], mean = mean.latent.response.nonsp.2)) +
                                   (pnorm(sample.tau[, "tau3.4"], mean = mean.latent.response.nonsp.3)
                                    - pnorm(sample.tau[, "tau3.3"], mean = mean.latent.response.nonsp.3))) / 3, 1, mean), prob = c(.025, .5, .975)),
                   quantile(apply(((1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.nonsp.1)) +
                                   (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.nonsp.1)) +
                                   (1 - pnorm(sample.tau[, "tau1.4"], mean = mean.latent.response.nonsp.1))) / 3, 1, mean), prob = c(.025, .5, .975)))

lower.bounds <- estimates[, 1]
plot.points <- estimates[, 2]
upper.bounds <- estimates[, 3]

plot.max <- max(upper.bounds)
plot.min <- min(lower.bounds)
plot.range <- plot.max - plot.min
pdf(file = paste("supportForGOPByNSP_", km.setting, "km.pdf", sep = ""), width = 7.2, height = 3)
par(mar = c(0, 3.5, 1, 0))
par(oma = c(0, 0, 0, 0))
x.temp <- as.numeric(matrix(c(seq(from = .9, to = 4.9, by = 1),
                              seq(from = 1.1, to = 5.1, by = 1)),
                            nrow = 2, ncol = 5))
plot(x.temp, plot.points,
     ylim = c(plot.min - .15 * plot.range, plot.max + .1 * plot.range),
     xlim = c(.5, 5.5),
     main = "",
     ylab = "",
     xlab = "",
     pch = rep(c(17, 25), each = 5),
     axes = FALSE, cex.lab = .8)
text(1:5, rep(plot.min - .1 * plot.range, times = 5),
     c("Not", "Unlikely", "Might", "Likely", "Certain"), cex = .8)
text(.8, plot.points[1], "Aid", adj = c(.5, .5), cex = .7)
text(1.3, plot.points[6], "No Aid", adj = c(.5, .5), cex = .7)
for(i in 1:10)
  lines(c(x.temp[i], x.temp[i]), c(lower.bounds[i], upper.bounds[i]))
abline(h = 0, lty = 2)
axis(side = 2, at = seq(from = 0, to = .6, by = .1), las = 2, cex.axis = .7)
mtext("Estimated Average\nPredicted Probability", side = 2, at = .25, cex = .8, line = 2)
dev.off()
